﻿import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts  1.12
import QtGraphicalEffects 1.12
import "./utils" as Utils
import Qt.labs.settings 1.0

Rectangle {
    signal compassEnableSignal(bool enable)
    signal dashBoardEnableSignal(bool v1, bool v2)
    signal hingeEnableSignal(bool enable)
    signal imuBoardEnableSignal(bool enable)
    Rectangle {
        color: "#20212C"
        anchors.fill: parent
        Text{
            x: 120
            y: 58
            color: "#FCFCFC"
            text: "大屏辅助线"
            font{
                family: "Inter"
                pixelSize: 32
            }
        }
        Text{
            x: 120
            y: 314
            color: "#FCFCFC"
            text: "安全检查"
            font{
                family: "Inter"
                pixelSize: 32
            }
        }
        Rectangle{
            x: 636
            y: 43
            width: 119
            height: 55
            border.color: Qt.rgba(1,1,1,0.5)
            border.width: 1
            radius: 8
            color: Qt.rgba(1,1,1,0)
            Text{
                anchors.centerIn: parent
                color: "#0085FF"
                text: "全部开启"
                font{
                    family: "PingFang HK"
                    pixelSize: 20
                }
            }
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    lineBtnRepeater.send_all_open(true)
                    safetyInspection.send_all_open(true)
                    compassBtn.opened = true
                }
            }
        }
        Rectangle{
            x: 773
            y: 43
            width: 119
            height: 55
            border.color: Qt.rgba(1,1,1,0.5)
            border.width: 1
            radius: 8
            color: Qt.rgba(1,1,1,0)
            Text{
                anchors.centerIn: parent
                color: "#0085FF"
                text: "全部关闭"
                font{
                    family: "PingFang HK"
                    pixelSize: 20
                }
            }
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    lineBtnRepeater.send_all_open(false)
                    safetyInspection.send_all_open(false)
                    compassBtn.opened = false
                }
            }
        }
        Column{
            x:168
            y:136
            spacing: 27
            Repeater{
                id: lineTextRepeater
                model: ["前轮行驶辅助线", "后轮行驶辅助线"]
                Text {
                    text: modelData
                    color: "#FCFCFC"
                    anchors.right: parent.right
                    font{
                        family: "Inter"
                        pixelSize: 24
                    }
                }
            }
        }
        Column{
            x:550
            y:130
            spacing: 24
            Repeater {
                id: lineBtnRepeater
                model: 2
                delegate:Utils.MySwitchBtn{
                    opened:true
                    onState: {
                        lineBtnRepeater.send_line_data()
                    }
                }
                function send_all_open(opened){
                    // console.log(lineBtnRepeater.count)
                    for(var i = 0 ; i < lineBtnRepeater.count; i++){
                        var item = lineBtnRepeater.itemAt(i)
                        item.opened = opened
                        // console.log(item.opened)
                    }
                }
                function send_line_data(){
                    if(lineBtnRepeater.itemAt(0) !== null &&lineBtnRepeater.itemAt(1) !== null)
                    {
                        var lineData = []
                        lineData.push(lineBtnRepeater.itemAt(0).opened);
                        lineData.push(0);
                        lineData.push(0);
                        lineData.push(0);
                        lineData.push(lineBtnRepeater.itemAt(1).opened);
                        can_manager.sendLineData(lineData)
                        image_manager.front_line_active = lineBtnRepeater.itemAt(0).opened
                        image_manager.back_line_active = lineBtnRepeater.itemAt(1).opened
                    }

                }
            }
        }
        Column{
            x:168
            y:390
            spacing: 27
            Repeater{
                id: safetyTextInspection
                model: ["开车前启动视野安全检查"]
                Text {
                    text: modelData
                    color: "#FCFCFC"
                    anchors.right: parent.right
                    font{
                        family: "Inter"
                        pixelSize: 24
                    }
                }
            }
        }
        Column{
            x:550
            y:384
            spacing: 24
            Repeater {
                id: safetyInspection
                model: 1
                delegate:Utils.MySwitchBtn{
                    opened:safetyInspectionSettings.safetyInspection
                    onState: {
                        safetyInspection.safetyInspectionState()
                    }
                }
                function send_all_open(opened){
                    // console.log(safetyInspection.count)
                    for(var i = 0 ; i < safetyInspection.count; i++){
                        var item = safetyInspection.itemAt(i)
                        item.opened = opened
                        // console.log(item.opened)
                    }
                }
                function safetyInspectionState() {
                    for(var i = 0 ; i < safetyInspection.count; i++){
                        // console.log("count and opened"+safetyInspection.count + " " + safetyInspection.itemAt(i).opened)
                        safetyInspectionSettings.safetyInspection = safetyInspection.itemAt(i).opened
                    }
                }
            }
        }
    }
}
